package StudyCode.summary.mycollection;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Set;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class FileToSet {
	public static Set<String> fileToSet(File file, boolean toLowerCase,
	                                    boolean trim) {
		try {
			Set<String> set = new HashSet<String>();
			BufferedReader br = new BufferedReader(new FileReader(file));
			String line = "";
			while ((line = br.readLine()) != null) {
				if (toLowerCase)
					set.add(line.toLowerCase());
				else if (trim)
					set.add(line.trim());
				else
					set.add(line);
			}
			if (set.isEmpty())
				return null;
			return set;
		} catch (Exception e) {
			return null;
		}
	}
}
